package com.jwthhealth_pub.old.report.view.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.report.model.resbody.HraDataRes;
import com.jwthhealth_pub.old.report.view.PhysicalStatDescActivity;
import com.jwthhealth_pub.old.report.view.ReportPhysicalActivity;

import java.util.ArrayList;

/**
 * Created by liuzhen on 2017/10/27.
 */

public class PhyStatAdapter extends RecyclerView.Adapter {
    private final ReportPhysicalActivity mActivity;
    private final String mHraType;
    private final ArrayList<HraDataRes.DataBean.ZjBean.SonBeanX.ShuomingBean> mData;

    public PhyStatAdapter(ReportPhysicalActivity reportPhysicalActivity, String hra_type, ArrayList<HraDataRes.DataBean.ZjBean.SonBeanX.ShuomingBean> shuoming) {
        this.mActivity = reportPhysicalActivity;
        this.mHraType = hra_type;
        this.mData = shuoming;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(mActivity, R.layout.item_phisical_status, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;
        final HraDataRes.DataBean.ZjBean.SonBeanX.ShuomingBean data = mData.get(vh.getAdapterPosition());

        final String desc = data.getValue();
        if (desc != null)
            vh.status.setText(desc);

        vh.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (desc == null) return;
                Intent intent = new Intent(mActivity, PhysicalStatDescActivity.class);
                intent.putExtra("desc", desc);
                intent.putExtra("title", mHraType);
                mActivity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {
        TextView status;
        LinearLayout clickLayout;

        public ViewHolder(View itemView) {
            super(itemView);
            status = itemView.findViewById(R.id.tv_status);
            clickLayout = itemView.findViewById(R.id.click_layout);
        }
    }
}
